package com.ruoyi.project.dict.handwriting.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.dict.handwriting.domain.Handwriting;
import com.ruoyi.project.dict.handwriting.service.IHandwritingService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 书法大全Controller
 * 
 * @author shixiangwen
 * @date 2020-02-13
 */
@Controller
@RequestMapping("/dict/handwriting")
public class HandwritingController extends BaseController
{
    private String prefix = "dict/handwriting";

    @Autowired
    private IHandwritingService handwritingService;

    @RequiresPermissions("dict:handwriting:view")
    @GetMapping()
    public String handwriting()
    {
        return prefix + "/handwriting";
    }

    /**
     * 查询书法大全列表
     */
    @RequiresPermissions("dict:handwriting:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Handwriting handwriting)
    {
        startPage();
        List<Handwriting> list = handwritingService.selectHandwritingList(handwriting);
        return getDataTable(list);
    }

    /**
     * 导出书法大全列表
     */
    @RequiresPermissions("dict:handwriting:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Handwriting handwriting)
    {
        List<Handwriting> list = handwritingService.selectHandwritingList(handwriting);
        ExcelUtil<Handwriting> util = new ExcelUtil<Handwriting>(Handwriting.class);
        return util.exportExcel(list, "handwriting");
    }

    /**
     * 新增书法大全
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存书法大全
     */
    @RequiresPermissions("dict:handwriting:add")
    @Log(title = "书法大全", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Handwriting handwriting)
    {
        return toAjax(handwritingService.insertHandwriting(handwriting));
    }

    /**
     * 修改书法大全
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Handwriting handwriting = handwritingService.selectHandwritingById(id);
        mmap.put("handwriting", handwriting);
        return prefix + "/edit";
    }

    /**
     * 修改保存书法大全
     */
    @RequiresPermissions("dict:handwriting:edit")
    @Log(title = "书法大全", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Handwriting handwriting)
    {
        return toAjax(handwritingService.updateHandwriting(handwriting));
    }

    /**
     * 删除书法大全
     */
    @RequiresPermissions("dict:handwriting:remove")
    @Log(title = "书法大全", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(handwritingService.deleteHandwritingByIds(ids));
    }
}
